<template>
    <div>
        <el-form  :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="检验方式编号" prop="InspectCode">
                <el-input v-model="model.InspectCode"></el-input>
            </el-form-item>

            <el-form-item label="检验方式名称" prop="InspectName">
                <el-input v-model="model.InspectName"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
export default {
    props: {
        model:{
            require:true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data(){
        return{
            QcWayList:[],
            rules:{
                    InspectCode:{required: true,message: '请输入编号',trigger: 'blur'},
                    InspectName:{required: true,message: '请输入名称',trigger: 'blur'}, 

            }
        }
    },
    created(){
        this.getQcWayAll();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid) => {
                if (valid){
                    if(this.isUpdate)
                    {
                        this.put();
                    }
                    else{
                        this.add();
                    }
                }
                else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm(){
            this.$refs['ruleForm'].resetFields();
        },
        add(){
            this.$http.postForm('/api/QcWay',{model:this.model},{loading:this.$loading()})
            .then(res=>{
                this.$emit('callback');
            })
        },
        put(){
            this.$http.putForm('/api/QcWay',{model:this.model},{loading:this.$loading()})
            .then((res)=>{
                this.$emit('callback');
            })
        },
        getQcWayAll(){
            this.$http.get('/api/QcWay/GetAll')
            .then(res=>{
                this.QcWayList=res.Data;
            })
        }
    }
}
</script>
<style></style>
